package com.whcoding.jwt.token.config;

import com.whcoding.jwt.token.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义拦截器配置
 * @author Manager
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

	@Bean
	public JwtInterceptor getTokenInterceptor() {
		return new JwtInterceptor();
	}

	/**
	 * 此处拦截路径（/**）
	 * 注意两个**。一个*号只拦截一级路径下，两个*号拦截所有
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(getTokenInterceptor())
				.addPathPatterns("/**")
				.excludePathPatterns("/login")
				.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**", "/bpm/**", "**/bpm/**", "/error/**", "/error");

	}
}
